package org.example.algorithm.greedy;

public class CanJumpSolution {

    public static void main(String[] args) {
        int[] nums = {3,2,1,0,4};
        CanJumpSolution solution = new CanJumpSolution();
        boolean res = solution.canJump(nums);
        System.out.println(res);
    }

    public boolean canJump(int[] nums) {
        int maxPos = 0;
        for (int i=0;i<nums.length;i++) {
            if (i > maxPos) {
                return false;
            }
            maxPos = Math.max(maxPos, i+nums[i]);
        }
        return true;
    }
}
